package quebralink;

import java.awt.Toolkit;
import java.awt.datatransfer.*;
import java.io.IOException;

/**
 *
 * @author ranishot
 */
public class ClipBoardUtil {

    public static String getClipboard() throws UnsupportedFlavorException, IOException {
        Transferable t = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null);


        if (t != null && t.isDataFlavorSupported(DataFlavor.stringFlavor)) {
            String text = (String) t.getTransferData(DataFlavor.stringFlavor);
            return text;
        }


        return null;
    }

    public static boolean copyToClipBoard(String text) {
        try {
            Clipboard cp = Toolkit.getDefaultToolkit().getSystemClipboard();
            StringSelection sl = new StringSelection(text);
            cp.setContents(sl, null);
        } catch (Exception e) {
            return false;
        }
        return true;
    }
}
